package com.hellpro.lolbox.home.collections;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hellpro.lolbox.R;
import com.hellpro.lolbox.bean.CollectBean;
import com.hellpro.lolbox.config.UrlConfigs;

import java.util.ArrayList;
import java.util.List;

/**
 * Package_Name: com.hellpro.lolbox.home.collections
 * Description :
 * author: HellPermanent
 * date:  2016/10/23 18:33
 * remarks：
 */
public class CollectAdapter extends BaseAdapter {
    private List<CollectBean> mList;
    public CollectAdapter(){
        mList = new ArrayList<>();
    }
    public  void setData(List<CollectBean> List){
mList = List;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return mList!=null?mList.size():0;
    }

    @Override
    public Object getItem(int position) {
        return mList!=null?mList.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder mHolder ;
        if (convertView==null) {
            convertView =LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_collect_list,parent,false);
            mHolder  = new Holder(convertView);
            convertView.setTag(mHolder);
        }else {
            mHolder = (Holder) convertView.getTag();
        }
        CollectBean collectBean = mList.get(position);
        String icon = collectBean.getIcon();
        int  m = Integer.parseInt(icon);
        String logoPath = UrlConfigs.ZHANJILOGO + m + ".jpg";
        Uri parse = Uri.parse(logoPath);
        mHolder.logo.setImageURI(parse);
        String pn = collectBean.getPn();
        mHolder.name.setText(pn);
        String qu= collectBean.getSn() + " " + collectBean.getSnFullName();
        mHolder.qu.setText( qu);
        String infros = collectBean.getTierDesc() + " " + collectBean.getZdl();
        mHolder.infro.setText(infros);

        return convertView;
    }


    static  class  Holder{
        SimpleDraweeView logo;
        TextView name;
        TextView qu;
        TextView infro;
        public  Holder(View view){
          logo = (SimpleDraweeView) view.findViewById(R.id.collect_listview_item_logo);
            name = (TextView) view.findViewById(R.id.collect_listview_item_pn);
          qu = (TextView) view.findViewById(R.id.collect_listview_item_sn_snfullname);
             infro = (TextView) view.findViewById(R.id.collect_listview_item_tier_zdl);

        }
    }
}
